package com.pb.infra.taskManage.controller;

import com.pb.infra.oth.entity.common.Page;
import com.pb.infra.oth.entity.common.Result;
import com.pb.infra.oth.util.Constant;
import com.pb.infra.oth.util.SysLog;
import com.pb.infra.taskManage.service.TaskControlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 *任务监控
 * @author liaohaoyuan
 * @date 20210501
 */
@Slf4j
@RestController
@RequestMapping("v1/taskManage/taskControl")
public class TaskControlController {

    /**
     * 业务逻辑对象
     */
    @Resource
    private TaskControlService taskControlService;

    /**
     * 日志操作表
     */
    private static final String TABLE_NAME = "MA_JOB_STATUS_SCHEDULE";

    /**
     * 日志操作功能名
     */
    private static final String OPERATION_MENU = "任务监控";

    /**
     * 查询分页数据
     * @param map 请求参数
     * @return Result 返回数据
     */
    @GetMapping("select")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result select(@RequestParam Map<String, Object> map,Page page) {
        return taskControlService.select(map,page);
    }

    /**
     * 查询最新日期数据
     * @param map 请求参数
     * @return Result 返回数据
     */
    @GetMapping("getLastDataDate")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result getLastDataDate(@RequestParam Map<String, Object> map) {
        return taskControlService.getLastDataDate(map);
    }
    /**
     * 验证重置可行性
     * @param map 请求参数
     * @return Result 返回数据
     */
    @PostMapping("doVldBfReset")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result doVldBfReset(@RequestBody Map<String, Object> map) {
        return taskControlService.doVldBfReset(map);
    }
    /**
     * 修改数据库用户
     *
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @PostMapping("doUpdateStatus")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.MOD, menuName = OPERATION_MENU)
    public Result doUpdateStatus(@RequestBody Map<String, Object> paramMap){
        try {
            Result insert = taskControlService.doUpdateStatus(paramMap);
            return insert;
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(Constant.EXIST, Constant.UPDATE_ERROR_MSG);
        }
    }

}
